package cn.com.zs.android.util;

import java.util.ArrayList;
import java.util.List;

import cn.com.zs.android.R;
import cn.com.zs.android.model.GameParams;

/**
 * 有关游戏的工具
 * @author 曾帅
 */
public class GameUtil {

	/** 游戏背景音乐列表 **/
	public static List<Integer> backgroundMusicList;
	
	static {
		if (backgroundMusicList == null) {
			backgroundMusicList = new ArrayList<Integer>();
		}
		backgroundMusicList.add(R.raw.background_music_1);
	}
	
	/**
	 * 取得游戏准备时间
	 */
	public static long getReadyTime() {
		if(GameParams.readyGameTime == -1L) {
			GameParams.readyGameTime = System.currentTimeMillis() + GameParams.startCountdownTime;
			return GameParams.startCountdownTime / 1000;
		}
		long nowTime = (GameParams.readyGameTime - System.currentTimeMillis()) / 1000;
		return nowTime < 0 ? 0 : nowTime;
	}
	
	/**
	 * 取得游戏进行时间
	 */
	public static long getGameTime() {
		if(GameParams.startGameTime == -1L) {
			GameParams.startGameTime = System.currentTimeMillis() + GameParams.gameCountdownTime;
			return GameParams.gameCountdownTime / 1000;
		}
		long nowTime = (GameParams.startGameTime - System.currentTimeMillis()) / 1000;
		return nowTime < 0 ? 0 : nowTime;
	}
	
	public static int getGameTimeImage() {
		double game_time;
		if(GameUtil.getReadyTime() > 0) {
			game_time = GameParams.gameCountdownTime / 1000;
		} else {
			game_time = (double) getGameTime() / (GameParams.gameCountdownTime / (1000 * 10));
		}
		int image ;
		switch ((int) Math.ceil(game_time)) {
		case 0:
			image = R.drawable.game_time_00;
			break;
		case 1:
			image = R.drawable.game_time_01;
			break;
		case 2:
			image = R.drawable.game_time_02;
			break;
		case 3:
			image = R.drawable.game_time_03;
			break;
		case 4:
			image = R.drawable.game_time_04;
			break;
		case 5:
			image = R.drawable.game_time_05;
			break;
		case 6:
			image = R.drawable.game_time_06;
			break;
		case 7:
			image = R.drawable.game_time_07;
			break;
		case 8:
			image = R.drawable.game_time_08;
			break;
		case 9:
			image = R.drawable.game_time_09;
			break;
		case 10:
			image = R.drawable.game_time_10;
			break;
		default:
			image = R.drawable.game_time_10;
			break;
		}
		return image;
	}
}
